<?xml version="1.0" encoding="UTF-8"?>

<!-- 
 * Copyright 2008 Philippe Prados.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
-->

<?xml-stylesheet type="text/xsl" href="../../../../xslt/xslt-to-xhtml.xslt" ?>
<!-- jboss/jaas/intranet -->
<!--
	http://labs.jboss.com/file-access/default/members/jbossas/freezone/docs/Server_Configuration_Guide/beta422/html/Defining_Security_Domains-The_DynamicLoginConfig_service.html
-->
<xsl:stylesheet 
	version="2.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation=
		"http://www.w3.org/1999/XSL/Transform http://www.w3.org/2007/schema-for-xslt20.xsd
		 http://jndi-resources.googlecode.com/1.0/ http://www.prados.fr/xsd/1.0/jndi-resources.xsd
		"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:jndi="http://jndi-resources.googlecode.com/1.0/"
	xmlns:tools="http://jndi-resources.googlecode.com/1.0/java/com.googlecode.jndiresources.tools.XSLTools"
	exclude-result-prefixes="#all"
>

	<xsl:variable name="jaasmodule">
		<xsl:value-of select="substring-after($familly,'jaas/')" />
	</xsl:variable>

	<xsl:template name="main">
		<xsl:value-of select="tools:fileCopy('../../../tools/xslt/save.xslt',concat($targetdir,'../xslt/'))"/>
		<xsl:value-of select="tools:info(concat('Generate ',$filename))" />
		<xsl:result-document href="{$filename}">
			<xsl:text>&#xA;</xsl:text>
			<xsl:comment>Generated by jndi-resources v<xsl:value-of select="$version" /></xsl:comment>
			<xsl:text>&#xA;</xsl:text>
			<xsl:processing-instruction name="jndi-stylesheet">
				<xsl:text>href="xslt/save.xslt" target="</xsl:text><xsl:value-of select="concat($basefilename,'.xml')" /><xsl:text>"</xsl:text>
			</xsl:processing-instruction>
			<xsl:text>&#xA;</xsl:text>
			<server>
					<xsl:variable name="login_config">
						<xsl:value-of select="concat($jaasmodule,'_login-config.xml')"/>
					</xsl:variable>
					<xsl:text>&#xA;   </xsl:text>
					<xsl:text>&#xA;   </xsl:text>
					<mbean
						code="org.jboss.security.auth.login.DynamicLoginConfig"
						name="{$currentid}:j2eeType=JAASResource,name={$login_config}">
						<attribute name="AuthConfig">
							<xsl:value-of select="$login_config" />
						</attribute>
						<depends optional-attribute-name="LoginConfigService">jboss.security:service=XMLLoginConfig</depends>
						<depends optional-attribute-name="SecurityManagerService">jboss.security:service=JaasSecurityManager</depends>
					</mbean>
				<xsl:apply-templates select="jndi:resource"/>
			</server>
		</xsl:result-document>
		<xsl:call-template name="login"/>
	</xsl:template>

	<xsl:template
		match="jndi:resources[@id=$currentid]/jndi:resource[@familly=$familly]">
		<xsl:text>&#xA;   </xsl:text>
		<xsl:text>&#xA;   </xsl:text>
		<mbean
			code="org.jboss.naming.NamingAlias"
			name="$currentid:j2eeType=JNDIResource,jndiName={@name}">
			<attribute name="ToName">java:jaas/<xsl:value-of select="$jaasmodule" /></attribute>
			<attribute name="FromName">java:<xsl:value-of select="@name" /></attribute>
			<depends>jboss:service=Naming</depends>
		</mbean>
	</xsl:template>

	<!-- Generate second file -->
	<xsl:template name="login">
		<xsl:variable name="basefilename">
			<xsl:value-of
				select="concat('conf/',$jaasmodule,'_login-config')" />
		</xsl:variable>
		<xsl:variable name="filename">
			<xsl:value-of
				select="concat($targetdir,'jboss.server.conf/',$basefilename,'.jndi')" />
		</xsl:variable>
		<xsl:value-of
			select="tools:info(concat('Generate ',$filename))" />
		<xsl:value-of
			select="tools:info(concat('Generate ',$filename))" />
		<xsl:result-document href="{$filename}">
			<xsl:text>&#xA;</xsl:text>
			<xsl:comment>Generated by jndi-resources v<xsl:value-of select="$version" /></xsl:comment>
			<xsl:text>&#xA;</xsl:text>
			<xsl:processing-instruction name="jndi-stylesheet">
				<xsl:text>href="xslt/save.xslt" target="</xsl:text><xsl:value-of select="concat($basefilename,'.xml')" /><xsl:text>"</xsl:text>
			</xsl:processing-instruction>
			<xsl:text>&#xA;</xsl:text>
			<xsl:copy-of select="$pattern" />
		</xsl:result-document>
	</xsl:template>

</xsl:stylesheet>

